<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title><spring:message code="message.lable.compinfoSTDsee"/></title>
 <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
<!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1><spring:message code="message.lable.compinfoSTDsee"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.StdManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.compinfoStd"/></a></li>
        </ol>
    </section>

    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
            <form action="${ctx}/stdCompinfo/exportExcel.html" id="exportExcel" method="post">
            <input id="fileName" name="fileName" type="hidden" value="<spring:message code="message.lable.compInfoxls"/>" />
                <div class="input">
                    <div class="textalign1"><spring:message code="message.listForm.qiYeMingCheng"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="compName" name="compName" placeholder="<spring:message code="message.listForm.qiYeMingCheng"/>"/>
                    </div>
                    
                    <div class="textalign"><spring:message code="message.listForm.qiYeBianMa"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="compCode" name="compCode" placeholder="<spring:message code="message.listForm.qiYeBianMa"/>"/>
                    </div>
                    
                    <div class="textalign"><spring:message code="message.listForm.qiYeLeiXing"/>：</div>
                    <div class="boxinput">
                        <select  class="textinput" id="selectId" name="compType">
                            <option value=""><spring:message code="message.select.option"/></option>
                            <option value="1"><spring:message code="message.listForm.shengChanQiYe"/></option>
                            <option value="2"><spring:message code="message.model.peiSongQiYe"/></option>
                        </select>
                    </div>
                </div>
                <div class="input" style="margin-top:-5px">
	                <div class="textalign1"><spring:message code="message.listForm.qiYeZhuCeLeiXing"/>：</div>
	                <div class="boxinput">
	                      <table style="width:100%;">
	                       <tr>
	                                    <td style="width:50%">
	                                      <select class="textinput" id="compRegId" name="compRegId1"></select>
	                                    </td>
	                                    <td style="width:50%">  
	                                      <select class="textinput" id="compRegId2" name="compRegId2"></select>
	                                    </td>
	                        </tr>              
	                      </table>   
	                 </div>
	                 <div class="textalign"><spring:message code="message.listForm.suoShuDiQu"/>：</div>
	                 <div class="boxinput">
	                       <table style="width:100%;">
	                           <tr>
	                              <td style="width:33%">
	                                <select class="textinput" id="area1" name="area1"></select>
	                              </td>
	                              <td style="width:33%">   
	                                <select class="textinput" id="area2" name="area2"></select>
	                                </td>
	                              <td style="width:33%">
	                                <select class="textinput" id="area3" name="area3"><option value=''><spring:message code="message.select.option"/></option></select>
	                              </td>
	                           </tr> 
	                        </table>
	                  </div>
	                  <div class="textalign"><spring:message code="message.lable.status"/>：</div>
	                  <div class="boxinput">
	                        <select class="textinput" name="status" id="status">
	                            <option value=""><spring:message code="message.select.option"/></option>
	                            <option value="1"><spring:message code="message.button.start"/></option>
	                            <option value="2"><spring:message code="message.button.stop"/></option>
	                            <option value="3"><spring:message code="message.button.combine"/></option>
	                        </select>
	                 </div>   
                </div>
                <div class="input">
                     <div class="textalign1" >
                           <button id="selectComp" type="button" onclick="likeQuery();" class="btn btn-success btn-sm"><spring:message code="message.button.seachSpacing"/></button>
                     </div>  
               </div>
            
            </form>
            </div>
          </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
            <ms:btn url="/stdCompinfo/stdCompinfoAddJsp.html"><a href="stdCompinfoAddJsp.html" class="btn btn-default btn-sm"><spring:message code="message.button.addSpacing"/></a></ms:btn>
            <ms:btn url="/stdCompinfo/enable.html"><label id="allOk" class="btn btn-default btn-sm"><spring:message code="message.button.startSpacing"/></label></ms:btn>
            <ms:btn url="/stdCompinfo/disable.html"><label id="allDelete" class="btn btn-default btn-sm"><spring:message code="message.button.stopSpacing"/></label></ms:btn> 
            <ms:btn url="/stdCompinfoDetail/toCompMergeJsp.html"><label id="combine" class="btn btn-default btn-sm"><spring:message code="message.button.combineSpacing"/></label></ms:btn>
        	<label onclick="exportExcel();" class="btn btn-default btn-sm"><spring:message code="message.lable.daoChu"/></label>
        </div>

        <form action="${ctx}/stdCompinfo/stdCompinfoEditJsp.html" id="FormSubmit" method="post">
            <input type="hidden" name="compId" id="compId" /> 
            <input type="hidden" name="compCode" id="compCodeEdit" /> 
            <input type="hidden" name="compName" id="compNameEdit" /> 
            <input type="hidden" name="compType" id="compType" /> 
            <input type="hidden" name="status" id="status" />
        </form>

        <form action="${ctx}/stdCompinfoDetail/toCompMergeJsp.html" id="Form" method="post">
            <input type="hidden" name="compIdMerge" id="compIdMerge" /> 
            <input type="hidden" name="statusMerge" id="statusMerge" />
        </form>
        <form action="${ctx}/stdCompinfo/toStdCompinfoSeltDetailJsp.html" id="FormDetail" method="post">
            <input type="hidden" name="compId" id="compCodeDetail" /> 
        </form>
    </section>
   <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script src="${ctx}/lib/plugins/daterangepicker/moment.js"></script>
    <script src="${ctx}/lib/plugins/daterangepicker/daterangepicker.js"></script>
    <script type="text/javascript">
    
     //绑定回车
    $('#compCode,#compName,#selectId,#compRegId,#compRegId2,#area1,#area2,#area3,#status').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectComp').click();
        }
    }); 
  
    $("#compName").focus();//加载页面光标在第一个查询框内
    
        $(function() {
            
            $('#allDelete').click(function(){
                batchChangeStatus(2);
            });
            $('#allOk').click(function(){
                batchChangeStatus(1);
            }); 
            
            
            
            $('#addNew').click(function() {
                $('#exampleModal').modal({
                    keyboard : true
                });
            });
              $("#area1").HNSelect({
                    url: "${pageContext.request.contextPath}/selectController/getArea.html", data: { ID: '000000' },  defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                    func: function () {
                        $("#area2").HNSelect({
                            parent_selector: "#area1", url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID",defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                                      func: function () {
                                          $("#area3").HNSelect({
                                              parent_selector: "#area2", url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID", defaultText: "<option value=''><spring:message code="message.select.option"/></option>"
                                          });
                                      }
                        });
                    }
                });
              $("#compRegId").HNSelect({
                    url: "${pageContext.request.contextPath}/selectController/getDicCompType.html", data: {compRegId:""},  defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                        func: function () {
                            $("#compRegId2").HNSelect({
                                parent_selector: "#compRegId", url: "${pageContext.request.contextPath}/selectController/getDicCompType.html", dataid: "compRegId",defaultText: "<option value=''><spring:message code="message.select.option"/></option>"
                            });
                        }
                });
              
            $("#gridlist").jqGrid({
                    url : "stdCompinfoList.html",
                    mtype : "POST",
                    datatype : "json",
                    autowidth : true,
                    shrinkToFit:false,
                    height : 270,
                    colNames : [ '<spring:message code="message.jqGrid.cz"/>' ,
                                 'id',
                                 '<spring:message code="message.listForm.qiYeBianMa"/>',
                                 'compName',
                                 '<spring:message code="message.listForm.qiYeMingCheng"/>', 
                                 '<spring:message code="message.listForm.qiYeLeiXing"/>',
                                 '<spring:message code="message.listForm.zuZhiJiGouDaiMa"/>', 
                                 '<spring:message code="message.listForm.suoShuDiQu"/>', 
                                 '<spring:message code="message.listForm.qiYeZhuCeLeiXing"/>', 
                                 '<spring:message code="message.lable.status"/>'
                                 ],
                    colModel : [
                            
                                
                                {name : 'operate',width : 100,align : "center",sortable : false,
                                    formatter : function(val, opts, rowdata) {
                                        var str=""; 
                                        str += "<ms:btn url='/stdCompinfo/stdCompinfoEditJsp.html'><a href=\"javascript:edit('"+ rowdata.compId+ "','"+ rowdata.compCode+ "','"+ rowdata.compName+ "','"+ rowdata.compType+ "','"+ rowdata.status+ "');\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.bianJi"/>'></a></ms:btn>";
                                        str += "<ms:btn url='/stdCompinfo/toStdCompinfoSeltDetailJsp.html'><a href=\"javascript:detail('"+ rowdata.compId+ "');\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -100px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.xiangQing"/>'></a></ms:btn>";
                                        str +="<ms:btn url='/stdCompinfoLog/stdCompinfoLogDetail.html'><a href='${ctx}/stdCompinfoLog/stdCompinfoLogDetail.html?compId="+ rowdata.compId+ "&compCode="+rowdata.compCode+"&compName="+rowdata.compName+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.weiHuJiLu"/>'></a></ms:btn>";
                                        return str;
                                    }
                                },
                                {name : 'compId',width : 100,align : "center",hidden : true,sortable : false},
                                {name : 'compCode',width : 180,align : "center",sortable : false},
                                {name : 'compName',width : 180,hidden:true,align : "left",sortable : false},
                                {name : 'compNameTag',width : 250,align : "left",sortable : false,
                                    formatter:function(val, opts, rowdata) {
                                         return "<a href=\"javascript:$.HN.dialog.opendialog('"+rowdata.compId+"','"+rowdata.compName+"','${ctx}/stdCompinfo/toStdCompinfoDetail.html?compId="+rowdata.compId+"','800px','400px',function operResult(val){return operResult;})\">"+rowdata.compName+"</a>";
                                	}   
                                },
                                {name : 'compType',width : 100,align : "center",sortable : false,
                                    formatter : function(val, opts,rowdata) {
                                        var str = "";
                                        if (rowdata.compType == 1) {
                                            str = "<spring:message code="message.listForm.shengChanQiYe"/>";
                                        }
                                        if (rowdata.compType == 2) {
                                            str = "<spring:message code="message.model.peiSongQiYe"/>";
                                        }
                                        return str;
                                    }
                                },
                                {name : 'orgCode',width : 120,align : "center",sortable : false},
                                {name : 'arFullname',width : 140,align : "center",sortable : false},
                                {name : 'compRegName',width : 120,align : "center",sortable : false},
                                {name : 'status',width : 60,align : "center",sortable : false,
                                	cellattr:function (rowId, val, rawObject, cm) {
                            	    	if(val == '<spring:message code="message.button.stop"/>'){
                            	    		return 'style="color:red"';
                            	    	}
                                    },
                                    formatter : function(val, opts,rowdata) {
                                        var str = "";
                                        if (rowdata.status == 1) {
                                            str += "<spring:message code="message.button.start"/>";
                                        }
                                        if (rowdata.status == 2) {
                                            str += "<spring:message code="message.button.stop"/>";
                                        }
                                        if (rowdata.status == 3) {
                                            str += "<spring:message code="message.button.combine"/>";
                                        }
                                        return str;
                                }
                            }
                    ],
                    rowNum : 20,
                    rowList : [ 10, 20, 50,100 ],
                    rownumbers : true,
                    pager : "#gridpage",
                    multiselect : true,
                    viewrecords : true,
                    caption : "<spring:message code="message.list.compinfoStdlist"/>",
                    gridComplete:function(){
                        //序号列宽度自适应（参数为jqgridID）
                        autoRNWidth("gridlist");
                        //数据只有一条时默认选中（参数为jqgridID）
                        selectByOneData("gridlist");
                    },
                    jsonReader : {
                        repeatitems : false,
                        id : "compId"
                    }
                });
        
            $("#gridlist").jqGrid('navGrid', '#gridpage', {add : false,edit : false,del : false,search : false,refresh : false});
            $(window).trigger("resize");
        });
        //tingyong
        function batchChangeStatus(status) {
             var msg = "";
             var url = "";
                if (status == 1){
                    msg = "<spring:message code="message.button.start"/>";
                    url = "${ctx}/stdCompinfo/disable.html";
                } else if (status == 2){
                    msg = "<spring:message code="message.button.stop"/>";
                    url = "${ctx}/stdCompinfo/enable.html";
                }
                
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.alert("<spring:message code="message.lable.pleaseSelect"/>"+msg+"<spring:message code="message.lable.de"/><spring:message code="message.list.compinfoStdMergelist"/>！", "warn");
                return;
            }
            
            var data = "";
            var list = [];
            for(var i = 0;i<rowIds.length;i++){
                var sta =  $("#gridlist").jqGrid('getRowData',rowIds[i]);
                var temp = sta.status.replace(/<.*?>/ig,"");
                if(temp != msg && temp != "<spring:message code="message.button.combine"/>"){
                    data += sta.compNameTag+",";
                    list.push({"compId":rowIds[i], "status":status});
                }else{
                    
                }  
            }
            if(data){
                data = data.substring(0,data.length-1);
            }else{
                $.alert("<spring:message code="message.lable.ninXuanZe"/><spring:message code="message.list.compinfoStdMergelist"/><spring:message code="message.lable.yiJingShi"/>"+msg+"<spring:message code="message.lable.zhuangTaiGTH"/>", "warn");
                return;
            }
            
            //获取选中的ID及对应的名字（参数:jqgridId,名字列名，状态列名，当前操作即列表中显示的值），返回infos[0]是ID串，infos[1]是名字串
            var infos = batchSwitchStatus("gridlist","compName","status","<spring:message code='message.listForm.qiYeMingCheng'/>");
            if ( !(infos instanceof Array)){
                return;
            }
            
            $.HN.message.confirm('<spring:message code="message.lable.OKYES"/>'+msg+'<spring:message code="message.lable.yiXia"/><spring:message code="message.list.compinfoStdMergelist"/><spring:message code="message.lable.ma"/><br/>'+infos[1], '', '').on(function (e) {
                if (e) {
            $.post(url, {
                "array" : json.jsonToString(list)
            }, function(result) {
                if (result.success) {
                    var page = $("#gridlist").jqGrid('getGridParam','page');
                    $.alert("<spring:message code="message.HN.alert.chengGong"/>"+msg+result.conditions.sum+"<spring:message code="message.lable.tiao"/><spring:message code="message.list.compinfoStdMergelist"/>", "success");
                    likeQuery(page);
                } else {
                    $.alert(result.msg || msg+"<spring:message code="message.HN.alert.shibai"/>！", "error");
                }
            }, "json");
                }
            });
            }
        //合并
        $('#combine').click(function() {
                var checked = false;
                $("input.cbox").each(function() {
                    if ($(this).is(":checked")) {
                        checked = true;
                        return false;
                    };
                });

                if (!checked) {
                    $.alert("<spring:message code="message.lable.pleaseSelect"/><spring:message code="message.button.combine"/><spring:message code="message.lable.de"/><spring:message code="message.list.compinfoStdMergelist"/>", "warn");
                } else {
                    var rowIds = $("#gridlist").jqGrid('getGridParam', 'selarrrow');
                    if (rowIds.length > 1) {
                        $.alert("<spring:message code="message.lable.zhiNengXuanDanGe"/><spring:message code="message.list.compinfoStdMergelist"/>", "warn");
                        return;
                    }
                    var rowdata = $("#gridlist").jqGrid('getRowData', rowIds);
                    var compId = rowdata.compId;
                    var status = rowdata.status;
                    if(status == "<spring:message code="message.button.stop"/>"){
                        $.alert("<spring:message code="message.button.stop"/><spring:message code="message.lable.de"/><spring:message code="message.list.compinfoStdMergelist"/><spring:message code="message.lable.wuFa"/><spring:message code="message.button.combine"/>！", "warn");
                        return;
                    } else if(status == "<spring:message code="message.button.combine"/>"){
                        $.alert("<spring:message code="message.button.combine"/><spring:message code="message.lable.de"/><spring:message code="message.list.compinfoStdMergelist"/><spring:message code="message.lable.wuFaZai"/><spring:message code="message.button.combine"/>！", "warn");
                        return;
                    }else{
                    $.HN.message.confirm('<spring:message code="message.lable.OKYES"/><spring:message code="message.lable.jinXing"/><spring:message code="message.button.combine"/><spring:message code="message.lable.ma"/>', '', '').on(function(e) {
                            if (e) {
                                $("#compIdMerge").val(compId);
                                $("#Form").submit();
                            }
                        });
                    }
                }
                
            
        });
        //编辑
        function edit(compId, compCode, compName, compType, status) {
            $("#compId").val(compId);
            $("#compCodeEdit").val(compCode);
            $("#compNameEdit").val(compName);
            $("#compType").val(compType);
            $("#status").val(status);
            $("#FormSubmit").submit();

        }
        //查询
        function likeQuery(page) {
            var compType = $("#selectId").val();
            var areaId = "";
            if( "" != $("#area1").val() ){
                areaId = $("#area1").val();
            }
            if( "" != $("#area2").val()){
                areaId = $("#area2").val();
            }
            if( "" != $("#area3").val()){
                areaId = $("#area3").val();
            }

            var compRegId = "";
            if( "" != $("#compRegId").val()){
                compRegId = $("#compRegId").val();
            }

            if( "" != $("#compRegId2").val()){
                compRegId = $("#compRegId2").val();
            }
            
            var compCode = $.trim($("#compCode").val());
            var compName = $.trim($("#compName").val());
            var status = $("#status").val();
        
            $("#gridlist").jqGrid('setGridParam',{
                    url : "${pageContext.request.contextPath}/stdCompinfo/stdCompinfoList.html",
                    datatype:'json',
                    postData:{
                        "compType":compType,
                        "areaId":areaId,
                        "compRegId":compRegId,
                        "compCode":compCode,
                        "compName":compName,
                        "status":status},
                    page : page||1
            }).trigger("reloadGrid");
        }
        
        function detail(compId){
            $("#compCodeDetail").val(compId);
            $("#FormDetail").submit();
        }
      
        //导出
        function exportExcel(){
	             $("#exportExcel").submit();
    	} 
    </script>
</body>
</html>









